﻿using Huasky.MyWrod.Core.Annotations;
using Huasky.MyWrod.Core.Db;

namespace Huasky.MyWrod.Application.Home.Services;

/// <summary>
/// 静态方法与实例方法的使用案例
/// </summary>
/// <param name="session"></param>
[HuaskyApiService]
public class HomeService(UserSession session)
{
    public SessionData Session { get; } = session.GetSessionData();

    internal static OrderEntity CreateOrder(OrderDto dto)
    {
        var order = dto.Adapt<OrderEntity>();
        using var db = new HuaskyDbContext();
        order.Id = Guid.NewGuid();
        db.Add(order);
        db.SaveChanges();
        return order;
    }

    internal ReportEntity CreateReport(ReportDto dto)
    {
        var report = dto.Adapt<ReportEntity>();
        report.Id = Guid.NewGuid();
        report.ReportStaffId = Session.StaffId;
        using var db = new HuaskyDbContext();
        db.Add(report);
        db.SaveChanges();
        return report;
    }

    internal static List<ReportEntity> GetReports()
    {
        using var db = new HuaskyDbContext();
        return db.Report.GetDbItems().ToList();
    }

}
